function executSql(){
	fDisPatchFlag = null;
	fStatus = null;
	fClosed = null;
	var field1 = $("#field1").val();
	var operator1 = $("#operator1").val();
	var value1 = $("#value1").val();
	if(field1 != "blank" && (field1 == "" || field1 == undefined || operator1 == "" || operator1 == undefined || value1 == "" || value1 == undefined)){
		swal_Tips("第一搜索组信息不完整，不能进行搜索");
		return false;
	}
	if(field1 == "fDepName")
		field1 = "fDepId";
	if(field1 == "fStockName")
		field1 = "fStockId";
	if(field1 == "fOrderBillNo")
		fOrderBillNo =value1;
	if(field1 == "fDisPatchFlag"){
		if(value1 == 1)
			fDisPatchFlag = 1;
	}
	if(field1 == "fStatus"){
		if(value1 == 1)
			fStatus = 1;
		else if(value1 == 5)
			fStatus = 5;
		else
			fStatus = 3;
	}
	if(field1 == "fClosed"){
		if(value1 == 0)
			fClosed = 0;
		else
			fClosed = null;
	
	}
	
//	if(field1.indexOf("Date") != -1){
//		field1 = "UNIX_TIMESTAMP(date_format("+field1+", '%Y-%m-%d'))";
//		value1 = "UNIX_TIMESTAMP("+value1+")";
//	}
	
	value1 = value1.trim();
	if(field1 == "fName"||field1 == "fNumber"){
		sqlCombine = "("+"ie"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 != "blank" && field1 != "fRwId" && field1 != "fDisPatchFlag" && field1 != "fStatus"  && field1 != "fClosed" && field1 != "fOrderBillNo"&& field1 != "fNumber" && field1 != "fName" && field1 != "fOperSN"&& field1 != "fOper"&& field1 != "fNote"&& field1 != "fDepId" && field1 != "fDate"   && field1 != "fCode"&& field1 != "fDisBiller"&& field1 != "fWorkerName"&& field1 != "fWorkCenter"&& field1 != "fStartDate"&& field1 != "fEndDate"&& field1 != "fOthQty"&& field1 != "fReworkQty"&& field1 != "fQty"&& field1 != "fDisOper"
		&& field1 != "fScrapQty" && field1 != "fForitemQty" && field1 != "icScrapQty" && field1 != "icForitemQty" && field1 != "fOkQty"  && field1 != "fBillNo" && field1 != "fIsLastOper"){
		sqlCombine = "("+field1+" "+switchOper(operator1,value1)+" )";

	}
	else if(field1 == "fCode" ){
		sqlCombine = "("+"d"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fOperSN" ||field1 == "fOper"){
		sqlCombine = "("+"c"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fNote"){
		sqlCombine = "("+"c"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fBillNo"){
		sqlCombine = "("+"ie"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fWorkerName"){
		sqlCombine = "("+"t"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fOthQty"||field1 == "fReworkQty"||field1 == "fQty" || field1 == "fScrapQty" || field1 == "fForitemQty"||field1 == "fIsLastOper"){
		sqlCombine = "("+"e"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "icScrapQty"){
		sqlCombine = "("+"ic"+"."+"fScrapQty"+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "icForitemQty"){
		sqlCombine = "("+"ic"+"."+"fForitemQty"+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fOkQty"){
		sqlCombine = "("+"ic"+"."+field1+" "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fDisBiller"){
		sqlCombine = "("+"u1"+"."+"name "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fWorkCenter"){
		sqlCombine = "("+"dt"+"."+"fItemID "+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fStartDate"){
		value1 = "UNIX_TIMESTAMP('"+value1+"')";
		sqlCombine = "(UNIX_TIMESTAMP(date_format(t.fDate, '%Y-%m-%d'))"+' '+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fEndDate"){
		value1 = "UNIX_TIMESTAMP('"+value1+"')";
		sqlCombine = "(UNIX_TIMESTAMP(date_format(e.fDate, '%Y-%m-%d'))"+' '+switchOper(operator1,value1)+" )";
	}
	else if(field1 == "fDisOper"){
		sqlCombine = "("+"d"+"."+"fOper"+switchOper(operator1,value1)+" )";
	}
	/*if(operator1 == "<>" && field1 != "fRwId" && field1 != "fDisPatchFlag" && field1 != "blank" && field1 != "fStatus" && field1 != "fClosed"){
		sqlCombine += " or ("+field1+" is NULL )" ;
	}*/
	if(field1 == "fRwId"){
		if(value1 == 1){
			sqlCombine = "(fNumber like '05.%' or fNumber like '5.%' or fNumber like '99.%')";
		}
		else{
			sqlCombine = "(fNumber not like '05.%' and fNumber not like '5.%' and fNumber not like '99.%')";
		}
	}
	for(var i = 2 ;i <= searchCount;i++){
		var index = i-1;
		var andOr = $("#andOr"+index).val();
		var field = $("#field"+i).val();
		var operator = $("#operator"+i).val();
		var value = $("#value"+i).val();
		if(field == "blank")
			continue;
		if(field != "blank" && (field == "" || field == undefined || operator == "" || operator == undefined || value == "" || value == undefined)){
			swal_Tips("第"+i+"搜索组信息不完整，不能进行搜索");
			return false;
		}
		if(field == "fDepName")
			field = "fDepId";
		if(field == "fStockName")
			field = "fStockId";
		if(field == "fDisPatchFlag"){
			if(value == 1)
				fDisPatchFlag = 1;
			continue;
		}
		if(field == "fStatus"){
			if(value == 1)
				fStatus = 1;
			else if(value == 5)
				fStatus = 5;
			else
				fStatus = 3;
			continue;
		}
		if(field == "fClosed"){
			if(value == 0)
				fClosed = 0;
			continue;
		}
	   if(field == "fOrderBillNo"){
		   fOrderBillNo =value;
			continue;
		}
	   
//	   if(field.indexOf("Date") != -1){
//			field1 = "UNIX_TIMESTAMP(date_format("+field+", '%Y-%m-%d'))";
//			value1 = "UNIX_TIMESTAMP("+field+")";
//		}
	   
		value = value.trim();
		if(sqlCombine == "" && field != "fRwId"&& field != "fOrderBillNo"&& field != "fNumber" && field != "fName" && field != "fOperSN"&& field != "fOper"&& field != "fNote"&& field != "fDepId" && field != "fDate"   && field != "fCode"&& field != "fDisBiller"&& field != "fWorkerName"&& field != "fWorkCenter"&& field != "fStartDate"&& field != "fEndDate"&& field != "fOthQty"&& field != "fReworkQty"&& field != "fQty"&& field != "fDisOper"
			&& field != "fScrapQty" && field != "fForitemQty" && field != "icScrapQty" && field != "icForitemQty"&& field != "fOkQty"  && field != "fBillNo"){
			sqlCombine += " ("+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fCode"){
			sqlCombine += " ("+"d"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fCode"){
			sqlCombine += " "+andOr +" ("+"d"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fName"){
			sqlCombine += " ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fName"){
			sqlCombine += " "+andOr +" ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fNumber"){
			sqlCombine += " ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fNumber"){
			sqlCombine += " "+andOr +" ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fOperSN"){
			sqlCombine += " ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fOperSN"){
			sqlCombine += " "+andOr +" ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fBillNo"){
			sqlCombine += " ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fBillNo"){
			sqlCombine += " "+andOr +" ("+"ie"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fOper"){
			sqlCombine += " ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fOper"){
			sqlCombine += " "+andOr +" ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fNote"){
			sqlCombine += " ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fNote"){
			sqlCombine += " "+andOr +" ("+"c"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fWorkerName"){
			sqlCombine += " ("+"t"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fWorkerName"){
			sqlCombine += " "+andOr +" ("+"t"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fOthQty"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fOthQty"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fReworkQty"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fReworkQty"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fIsLastOper"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fIsLastOper"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fScrapQty"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fScrapQty"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fForitemQty"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fForitemQty"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "icScrapQty"){
			sqlCombine += " ("+"ic"+"."+"fScrapQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "icScrapQty"){
			sqlCombine += " "+andOr +" ("+"ic"+"."+"fScrapQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "icForitemQty"){
			sqlCombine += " ("+"ic"+"."+"fForitemQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "icForitemQty"){
			sqlCombine += " "+andOr +" ("+"ic"+"."+"fForitemQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fOkQty"){
			sqlCombine += " ("+"ic"+"."+"fOkQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fOkQty"){
			sqlCombine += " "+andOr +" ("+"ic"+"."+"fOkQty"+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fQty"){
			sqlCombine += " ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fQty"){
			sqlCombine += " "+andOr +" ("+"e"+"."+field+" "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fDisBiller"){
			sqlCombine += " ("+"u1"+"."+"name "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fDisBiller"){
			sqlCombine += " "+andOr +" ("+"u1"+"."+"name "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fWorkCenter"){
			sqlCombine += " ("+"dt"+"."+"fItemID "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fWorkCenter"){
			sqlCombine += " "+andOr +" ("+"dt"+"."+"fItemID "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fStartDate"){
			value = "UNIX_TIMESTAMP('"+value+"')";
			sqlCombine += " (UNIX_TIMESTAMP(date_format(t.fDate, '%Y-%m-%d'))"+' '+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fStartDate"){
			value = "UNIX_TIMESTAMP('"+value+"')";
			sqlCombine += " "+andOr +" (UNIX_TIMESTAMP(date_format(t.fDate, '%Y-%m-%d'))"+' '+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fEndDate"){
			value = "UNIX_TIMESTAMP('"+value+"')";
			sqlCombine += " (UNIX_TIMESTAMP(date_format(e.fDate, '%Y-%m-%d'))"+' '+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fEndDate"){
			value = "UNIX_TIMESTAMP('"+value+"')";
			sqlCombine += " "+andOr +" (UNIX_TIMESTAMP(date_format(e.fDate, '%Y-%m-%d'))"+' '+switchOper(operator,value)+" )";
		}
		else if (sqlCombine == "" && field == "fDisOper"){
			sqlCombine += " ("+"d"+"."+"fOper "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field == "fDisOper"){
			sqlCombine += " "+andOr +" ("+"d"+"."+"fOper "+switchOper(operator,value)+" )";
		}
		else if (sqlCombine != "" && field != "fRwId" && field != "fNumber" && field != "fName"){
			sqlCombine += " "+andOr +" ("+field+" "+switchOper(operator,value)+" )";
		}
		else if(sqlCombine == "" && field == "fRwId"){
			if(value == 1){
				sqlCombine += "(fNumber like '05.%' or fNumber like '5.%' or fNumber like '99.%')"
			}
			else{
				sqlCombine += "(fNumber not like '05.%' and fNumber not like '5.%' and fNumber not like '99.%')"
			}
		}
		else{
			if(value == 1){
				sqlCombine +=  " "+andOr +"(fNumber like '05.%' or fNumber like '5.%' or fNumber like '99.%')"
			}
			else{
				sqlCombine +=  " "+andOr +"(fNumber not like '05.%' and fNumber not like '5.%' and fNumber not like '99.%')"
			}
		}
		
		/*if(operator == "<>" && field != "fRwId" && field != "blank"){
			sqlCombine += " or ("+field+" is NULL )" ;
		}*/
	}
	console.log(sqlCombine);
	for(var l = 1 ;l <= searchCount;l++){
		if(sqlCombine.indexOf("fName")!=-1){
			$("#value"+l).unbind().bind("keyup",function (event) {
				if(event.keyCode == "118"){
					IDName = event.target.id;
					jj=IDName.substring(5);
					console.log(jj);
					$("#queryName").text("查询-物料代码");
					$("#ERPModal").modal('show');
				}
				if (event.keyCode == 13) { 
					$('#query').triggerHandler('click'); 
				}
			});
			
		}else if(sqlCombine.indexOf("fNumber")!=-1){
			$("#value"+l).unbind().bind("keyup",function (event) {
				if(event.keyCode == "118"){
					IDName = event.target.id;
					jj=IDName.substring(5);
					$("#queryName").text("查询-物料代码");
					$("#ERPModal").modal('show');
				}
				if (event.keyCode == 13) { 
					$('#query').triggerHandler('click'); 
				}
			});
		}else if(sqlCombine.indexOf("fModel")!=-1){
			$("#value"+l).unbind().bind("keyup",function (event) {
				if(event.keyCode == "118"){
					IDName = event.target.id;
					jj=IDName.substring(5);
					$("#queryName").text("查询-物料代码");
					$("#ERPModal").modal('show');
				}
				if (event.keyCode == 13) { 
					$('#query').triggerHandler('click'); 
				}
			});
		}
		else{
			$("#value"+l).unbind().bind("keyup",function (event) {
				if(event.keyCode == "118"){
					IDName = event.target.id;
					jj=IDName.substring(5);
					$("#queryName").text("查询-物料代码");
					$("#ERPModal").modal('show');
				}
				if (event.keyCode == 13) { 
					$('#query').triggerHandler('click'); 
				}
			});
		}
	}
}
function switchOper(operator,value){
	var statement;
	switch(operator){
	case 'like':
		statement = "like "+"'%"+value+"%'";
		break;
	case 'left like':
		statement = "like "+"'"+value+"%'";
		break;
	case 'right like':
		statement = "like "+"'%"+value+"'";
		break;
	default:
		if(value.indexOf('UNIX_TIMESTAMP') != -1){
			statement = operator+" "+value;
		}else{
			statement = operator+" '"+value+"'";
		}
	}
	return statement;
}